home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / src / portable / addchstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.7 KB  |  284 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. #define    CURSES_LIBRARY    1
  20. #include <curses.h>
  21.  
  22. /* undefine any macros for functions defined in this module */
  23. #undef    addchstr
  24. #undef    addchnstr
  25. #undef    waddchstr
  26. #undef    waddchnstr
  27. #undef    mvaddchstr
  28. #undef    mvaddchnstr
  29. #undef    mvwaddchstr
  30. #undef    mvwaddchnstr
  31.  
  32. /* undefine any macros for functions called by this module if in debug mode */
  33. #ifdef PDCDEBUG
  34. #  undef    move
  35. #  undef    wmove
  36. #endif
  37.  
  38. #ifdef PDCDEBUG
  39. char *rcsid_addchstr  = "$Id$";
  40. #endif
  41.  
  42. /*man-start*********************************************************************
  43.  
  44.   Name:                                                        addchstr
  45.  
  46.   Synopsis:
  47.       int addchstr(chtype *ch);
  48.       int addchnstr(chtype *ch, int n);
  49.       int waddchstr(WINDOW *win, chtype *ch);
  50.       int waddchnstr(WINDOW *win, chtype *ch, int n);
  51.       int mvaddchstr(int y, int x, chtype *ch);
  52.       int mvaddchnstr(int y, int x, chtype *ch, int n);
  53.       int mvwaddchstr(WINDOW *, int y, int x, chtype *ch);
  54.       int mvwaddchnstr(WINDOW *, int y, int x, chtype *ch, int n);
  55.  
  56.   X/Open Description:
  57.      These routines write a chtype directly into the window structure
  58.      starting at the current position.
  59.      The four routines with n as the last argument copy at most n
  60.      elements, but no more than will fit on the line.
  61.      If n=-1 then the whole string is copied, to the maximum number
  62.      that will fit on the line.
  63.  
  64.      The cursor position is not advanced. These routines do not check for
  65.      newline or other special characters, no does any line wrapping occur.
  66.  
  67.      NOTE:    addchstr(), mvaddchstr(), mvwaddchstr() addchnstr(), 
  68.          mvaddchnstr(), and mvwaddchnstr() are implemented as macros.
  69.  
  70.   X/Open Return Value:
  71.      All functions return OK on success and ERR on error.
  72.  
  73.   X/Open Errors:
  74.      No errors are defined for this function.
  75.  
  76.   Portability                             X/Open    BSD    SYS V
  77.                                           Dec '88
  78.       addchstr                              -        -      4.0
  79.       waddchstr                             -        -      4.0
  80.       mvaddchstr                            -        -      4.0
  81.       mvwaddchstr                           -        -      4.0
  82.       addchnstr                             -        -      4.0
  83.       waddchnstr                            -        -      4.0
  84.       mvaddchnstr                           -        -      4.0
  85.       mvwaddchnstr                          -        -      4.0
  86.  
  87. **man-end**********************************************************************/
  88.  
  89. /***********************************************************************/
  90. int    addchstr(chtype *ch)
  91. /***********************************************************************/
  92. {
  93.     int i;
  94. #ifdef PDCDEBUG
  95.     if (trace_on) PDC_debug("addchstr() - called\n");
  96. #endif
  97.  
  98.     return( addchnstr( ch, -1) );
  99. }
  100. /***********************************************************************/
  101. int    addchnstr(chtype *ch, int n)
  102. /***********************************************************************/
  103. {
  104.     int y,x,num,maxx;
  105.     chtype *ptr,*saveptr;
  106. #ifdef PDCDEBUG
  107.     if (trace_on) PDC_debug("addchnstr() - called\n");
  108. #endif
  109.  
  110.     if (stdscr == (WINDOW *)NULL)
  111.         return( ERR );
  112.  
  113.     if (n == 0
  114.     ||  n < (-1))
  115.         return( ERR );
  116.  
  117.     x = stdscr->_curx;
  118.     y = stdscr->_cury;
  119.     ptr = &(stdscr->_y[y][x]);
  120.  
  121.  
  122.     if (n == (-1))
  123.         {
  124.         for (num = stdscr->_maxx - x; *ch && num--; num++)
  125.             *ptr++ = *ch++;
  126.             maxx = num;
  127.         }
  128.     else
  129.         {
  130.         num = min(stdscr->_maxx - x,n);
  131.         memcpy((char *)ptr, (char *)ch, (int)(num * sizeof(chtype)));
  132.         maxx = x+num-1;
  133.         }
  134.  
  135.     if (stdscr->_firstch[y] ==    _NO_CHANGE)
  136.         {
  137.         stdscr->_firstch[y] = x;
  138.         stdscr->_lastch[y] = maxx;
  139.         }
  140.     else
  141.         {
  142.         if (x <    stdscr->_firstch[y])
  143.             {
  144.             stdscr->_firstch[y] = x;
  145.             }
  146.         if (maxx >    stdscr->_lastch[y])
  147.             {
  148.             stdscr->_lastch[y] = maxx;
  149.             }
  150.         }
  151.     return( OK );
  152. }
  153. /***********************************************************************/
  154. int    waddchstr(WINDOW *win, chtype *ch)
  155. /***********************************************************************/
  156. {
  157. #ifdef PDCDEBUG
  158.     if (trace_on) PDC_debug("waddchstr() - called\n");
  159. #endif
  160.  
  161.     if (win == (WINDOW *)NULL)
  162.         return( ERR );
  163.  
  164.     return( waddchnstr( win, ch, -1) );
  165. }
  166. /***********************************************************************/
  167. int    waddchnstr(WINDOW *win, chtype *ch, int n)
  168. /***********************************************************************/
  169. {
  170.     int y,x,num,maxx;
  171.     chtype *ptr,*saveptr;
  172. #ifdef PDCDEBUG
  173.     if (trace_on) PDC_debug("waddchnstr() - called\n");
  174. #endif
  175.  
  176.     if (win == (WINDOW *)NULL)
  177.         return( ERR );
  178.  
  179.     if (n == 0
  180.     ||  n < (-1))
  181.         return( ERR );
  182.  
  183.     x = win->_curx;
  184.     y = win->_cury;
  185.     ptr = &(win->_y[y][x]);
  186.  
  187.  
  188.     if (n == (-1))
  189.         {
  190.         for (num = win->_maxx - x; *ch && num--; num++)
  191.             *ptr++ = *ch++;
  192.             maxx = num;
  193.         }
  194.     else
  195.         {
  196.         num = min(win->_maxx - x,n);
  197.         memcpy((char *)ptr, (char *)ch, (int)(num * sizeof(chtype)));
  198.         maxx = x+num-1;
  199.         }
  200.  
  201.     if (win->_firstch[y] ==    _NO_CHANGE)
  202.         {
  203.         win->_firstch[y] = x;
  204.         win->_lastch[y] = maxx;
  205.         }
  206.     else
  207.         {
  208.         if (x <    win->_firstch[y])
  209.             {
  210.             win->_firstch[y] = x;
  211.             }
  212.         if (maxx >    win->_lastch[y])
  213.             {
  214.             win->_lastch[y] = maxx;
  215.             }
  216.         }
  217.     return( OK );
  218. }
  219. /***********************************************************************/
  220. int    mvaddchstr(int y, int x, chtype *ch)
  221. /***********************************************************************/
  222. {
  223. #ifdef PDCDEBUG
  224.     if (trace_on) PDC_debug("mvaddchstr() - called: y %d x %d\n",y,x);
  225. #endif
  226.  
  227.     if (stdscr == (WINDOW *)NULL)
  228.         return( ERR );
  229.  
  230.     if (wmove(stdscr,y,x) == ERR)
  231.         return( ERR );
  232.  
  233.     return( addchnstr( ch, -1) );
  234. }
  235. /***********************************************************************/
  236. int    mvaddchnstr(int y, int x, chtype *ch, int n)
  237. /***********************************************************************/
  238. {
  239. #ifdef PDCDEBUG
  240.     if (trace_on) PDC_debug("mvaddchnstr() - called: y %d x %d n %d\n",y,x,n);
  241. #endif
  242.  
  243.     if (stdscr == (WINDOW *)NULL)
  244.         return( ERR );
  245.  
  246.     if (wmove(stdscr,y,x) == ERR)
  247.         return( ERR );
  248.  
  249.     return( addchnstr( ch, n) );
  250. }
  251. /***********************************************************************/
  252. int    mvwaddchstr(WINDOW *win, int y, int x, chtype *ch)
  253. /***********************************************************************/
  254. {
  255. #ifdef PDCDEBUG
  256.     if (trace_on) PDC_debug("waddchstr() - called:\n");
  257. #endif
  258.  
  259.     if (win == (WINDOW *)NULL)
  260.         return( ERR );
  261.  
  262.     if (wmove(win,y,x) == ERR)
  263.         return( ERR );
  264.  
  265.     return( waddchnstr( win, ch, -1) );
  266. }
  267. /***********************************************************************/
  268. int    mvwaddchnstr(WINDOW *win,int y, int x, chtype *ch, int n)
  269. /***********************************************************************/
  270. {
  271. #ifdef PDCDEBUG
  272.     if (trace_on) PDC_debug("mvwaddchnstr() - called: y %d x %d n %d \n",y,x,n);
  273. #endif
  274.  
  275.     if (win == (WINDOW *)NULL)
  276.         return( ERR );
  277.  
  278.     if (wmove(win,y,x) == ERR)
  279.         return( ERR );
  280.  
  281.     return( waddchnstr( win, ch, n) );
  282. }
  283.